package com.usian.behavior.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.behavior.ApLikesBehaviorControllerApi;
import com.usian.behavior.service.ApLikesBehaviorService;
import com.usian.model.behavior.dtos.LikesBehaviorDto;
import com.usian.model.behavior.pojos.ApLikesBehavior;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/likes_behavior")
public class ApLikesBehaviorController implements ApLikesBehaviorControllerApi {

    @Autowired
    private ApLikesBehaviorService apLikesBehaviorServiceI;

    @Override
    @PostMapping
    public ResponseResult likeOrUnlike(@RequestBody LikesBehaviorDto dto) {

        return apLikesBehaviorServiceI.likeOrUnlike(dto);
    }

    @Override
    @GetMapping("queryLikesByEntryIdAndArticleId")
    public ApLikesBehavior queryLikesByEntryIdAndArticleId(@RequestParam Integer entryId,
                                                           @RequestParam Long articleId,
                                                           @RequestParam Short type) {
        return apLikesBehaviorServiceI.getOne(
                Wrappers.<ApLikesBehavior>lambdaQuery()
                        .eq(ApLikesBehavior::getEntryId, entryId)
                        .eq(ApLikesBehavior::getArticleId, articleId)
                        .eq(ApLikesBehavior::getType, type));
    }


}
